package com.seari.client;

import com.seari.bean.CYMaxFullLoadBean;
import com.seari.service.AppCacheService;
import com.seari.service.FullLoadService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName CYMaxFullLoadClient
 * @Description 城运最高满咋率接口
 * @Author LANDSUS
 * @Date 2021/5/16 10:35
 * @Version 1.0
 */
@Component("CYMaxFullLoadClient")
public class CYMaxFullLoadClient extends BaseClient{

    protected static Logger log = LoggerFactory.getLogger(CYMaxFullLoadClient.class);

    @Autowired
    private FullLoadService service;

    @Autowired
    private AppCacheService appCacheService;


    @Override
    public void process() throws Exception {
        List<CYMaxFullLoadBean> topTen = null;
        try {
            topTen = service.avgAndMaxFullLoad4Line();
        }catch (RuntimeException e){
            log.error(e.getMessage());
        }
        if(topTen != null && topTen.size() > 0){
            log.info("cyMaxFullLoad get successfully");
            appCacheService.refreshCache("cyMaxFullLoad",topTen);
            log.info("cyMaxFullLoad save cache successfully");
        }else {
            log.info("cyMaxFullLoad get failed,doesn't save cache");
        }
    }
}
